1 Background

The objective of this study was to examine how non-autistic and autistic process social rewards, and whether participants would be able to learn whether two individuals were more similar or dissimilar to them. Prior to the fMRI scan, participants completed a survey of their interests (e.g. I am an animal lover). Using this survey, with over 200 responses, we matched other real participants to each other, such that every participant had a similar peer which shared 75% of the same interests, and a dissimilar peer which shared only 25% of the same interests. In the fMRI task, participants were shown an individuals name, either Shiloh or Charlie. These were the similar or dissimilar peers. For each trial, participants were first shown the peer’s name, then their own response to a survey question (e.g. animal lover indicating that the participant had responded that they love animals). Next, participants had to press a button to learn about the shown peer. The feedback consisted of a thumbs up with a “Me too!” message or a thumbs down with a “Not me!” message, indicating whether the peer had shared that interest or not. There was also a computer peer condition in which the computer gave 50% positive feedback as a “match” or “no match”.

1.1 Task Design

Social Reward Task
Social Reward Task

This was an event-related design with four runs of the task.

1.2 Setup Up

1.2.1 Import Packages

library(dplyr)
library(tidyr)
library(ggplot2)
library(emmeans)
library(lmerTest)
require(gridExtra)
library(multcomp)
library(plyr)
library(sjPlot)

1.2.2 Define directories

data_dir <- 'derivatives/task_socialreward/data/'

1.2.3 Find participants

subj_df <- read.csv('participants.tsv', sep = '\t')

# Remove prefix from subject IDs
subj_df$participant_id<-gsub("sub-SCN","SCN_",as.character(subj_df$participant_id))

print(paste('Found ', length(subj_df$participant_id), ' participants'))
## [1] "Found  114  participants"

2 Data Cleaning

Task errors: The task programming had an error which would show the participant incorrect options for their own preferences (e.g. would show “like animals”, when the participant said they didn’t like animals). We will remove participants for which this occurred a lot (more than 5 trials).

# Create an empty dataframe to fill with all the participant data
rt_data <- data.frame(matrix(ncol = 6, nrow = 0))

# Name columns for the empty dataframe  
colnames(rt_data) <- c('ParticipantID', 'Run', 'X', 'rating', 'ConditionName', 
                       'Correct_RT')


# Import Data

for (subj in subj_df$participant_id) {
  
  # Find data for all runs
  run_files <- Sys.glob(paste(data_dir, subj, '/*-errors.csv', sep = ''))
  
  # Loop through runs and combine into one df
  for (run_file in run_files){
    temp_run_data <- read.csv(run_file)
    
    # Only include participant data if there were no task errors
    if (sum(temp_run_data$redcap_v_task) == 0) {
      
      # Filter for relevant columns
      temp_run_data_fltr <- temp_run_data[,colnames(rt_data)]
      
      # Append to entire df
      rt_data <- rbind(rt_data, temp_run_data_fltr)
    } 
  }
}

# Rename trial number column 
names(rt_data)[names(rt_data) == 'X'] <- 'trial_num'

Add group (e.g. autistic, non-autistic) info to reaction time dataframe

rt_data <- merge(rt_data, subj_df, 
                 by.x = 'ParticipantID', by.y = 'participant_id')

# Rename column
rt_data <- rt_data %>% rename_at('ParticipantID', ~'participant_id')

Create column for the peer conditions info and valence of feedback

rt_data <- rt_data %>% separate(ConditionName, c('Valence', 'Condition'))

rt_data$Valence <- gsub('LowReward','negative',as.character(rt_data$Valence))
rt_data$Valence <- gsub('HighReward','positive',as.character(rt_data$Valence))

Calculate the valence of the previous trial within each condition

# Create an empty column of NAs
rt_data$Valence_prev <- NA

for (subj in unique(rt_data$participant_id)) {
  # Create a list of the runs for this participant
  temp_run_list <- unique(rt_data[rt_data$participant_id == 'SCN_101', 'Run'])
  
  for (run in temp_run_list) {
    
    for (cond in c('SimPeer', 'DisPeer', 'Computer')) {
      
      # Calculate the number of trials for a given condition per run per subject
      temp_len <- length(rt_data[rt_data$participant_id == subj & 
                                 rt_data$Run == run & 
                                 rt_data$Condition == cond, 'Valence'])
      
      # Create a list of the trial valences, excluding the first trial of that run
      # since nothing was shown before that trial in the run
      temp_val <- rt_data[rt_data$participant_id == subj & 
                          rt_data$Run == run & 
                          rt_data$Condition == cond, 'Valence'][1:temp_len-1]
      
      # Fill in the previous trial valence for that condition
      rt_data[rt_data$participant_id == subj & 
              rt_data$Run == run & 
              rt_data$Condition == cond, 'Valence_prev'] <- c(NA, temp_val)
    }
  }

}

Make group data an nominal data type

rt_data$group <- gsub('1','non-autistic',as.character(rt_data$group))
rt_data$group <- gsub('2','autistic',as.character(rt_data$group))
head(rt_data)

2.1 Demographic info

demo_info <- read.csv('misc/SCONNChildPacket-IdentifyingInfo_DATA_2024-05-13_1121.csv')
demo_info <- demo_info[demo_info$redcap_event_name == 'time_1_arm_1', ]
demo_info$record_id <- toupper(demo_info$record_id)

demo_info <- demo_info[which((demo_info$record_id %in% unique(rt_data$participant_id))==TRUE),]

mean(as.numeric(demo_info$child_exact_age), na.rm=TRUE)
## Warning in mean(as.numeric(demo_info$child_exact_age), na.rm = TRUE): NAs
## introduced by coercion
## [1] 13.04377
sd(as.numeric(demo_info$child_exact_age), na.rm=TRUE)
## Warning in is.data.frame(x): NAs introduced by coercion
## [1] 1.133389
table(demo_info$child_gender_lab_entered)
## 
##  1  2  4  5 
## 56 36  2  1

2.2 Missed trials

When a participant did not press the correct button, the feedback was “no data”. This occurred in two instances:

  • When the participant made no button press
  • When the participant hit the incorrect button, and did not hit the correct button before the trial timed out

In both these instances, the participant was not paying attention and so we should exclude these trials. If this was the case for more than 20% of the run, then we should exclude data from the entire run.

# Find participant runs with more than 20% missed trials

exclude_subj_runs <- data.frame(participant_id = character(), Run = character(), stringsAsFactors = FALSE)

# Create a list of all subject IDs
subj_list <- unique(rt_data$participant_id)

for (subj in subj_list) {
  
  # Filter for subject specific data
  temp_subj_data <- rt_data[rt_data$participant_id == subj, ]
  
  # Find runs per subject
  temp_runs <- unique(temp_subj_data$Run)
  
  for (run in temp_runs) {
    
    # Filter for run specific data
    temp_run_rt <- temp_subj_data[temp_subj_data$Run == run, 'Correct_RT']
    
    # Calculate the percentage of missed trials
    temp_na_perc <- sum(is.na(temp_run_rt)) / length(temp_run_rt)
    
    # If more than 20% missed trials, exclude the participant run
    if (temp_na_perc > 0.20) {
      exclude_subj_runs[nrow(exclude_subj_runs) + 1,] <- c(subj, run)
    }
  }
}

print(paste('Excluding',nrow(exclude_subj_runs),'runs from',
            length(unique(exclude_subj_runs$participant_id)),
            'participants'))
## [1] "Excluding 3 runs from 3 participants"

Use the list of bad participant runs to remove that data from the larger dataframe

for (i in 1:nrow(exclude_subj_runs)) {
  temp_drop_idx <- which(rt_data$participant_id == exclude_subj_runs[i, "participant_id"] & 
                         rt_data$Run == exclude_subj_runs[i, "Run"])
  
  rt_data <- rt_data[-temp_drop_idx, ]
}

With the remaining data, create column for missing trials. This might be interesting as it could be an indicator of learning. For example, if participants have learned who the dissimilar peer is, perhaps they would respond less for those trials than the similar peer trials. Accurate button presses will be coded as 1, and inaccurate will be coded as 0.

rt_data$accuracy <- 1
rt_data[is.na(rt_data$Correct_RT),'accuracy'] <- 0

table(rt_data$accuracy)
## 
##    0    1 
##  102 7758

Add run as a categorical variable (don’t end up using)

rt_data$Run.f <- factor(rt_data$Run)

2.3 Transforming Data

Using method from Jones et al., 2014: “Reaction times to the cue after the wink occurred were z-score transformed to each individual’s mean and standard deviation after first removing outliers (defined as reaction times 3 standard deviations above or below the individual’s mean reaction time) and log transforming each reaction time to satisfy normality assumptions.”

# Create copy of the data
rt_data_mod <- data.frame(rt_data)

# Remove outliers greater than 3SD
#rt_data_mod[( rt_data_mod$ParticipantID %in% "SCN_101" & rt_data_mod$Correct_RT > 3*temp_sd),]

# Log transform
rt_data_mod$Correct_RT_log <- log(rt_data$Correct_RT)

# Create empty column for log zscored data
rt_data_mod$Correct_RT_logz <- NA

for (subj in subj_df$participant_id) {
# Calculate mean and SD
  temp_subj_data <- filter(rt_data_mod, participant_id == subj)
  temp_mean <- mean(temp_subj_data$Correct_RT_log, na.rm = TRUE)
  temp_sd <- sd(temp_subj_data$Correct_RT_log, na.rm = TRUE)
  rt_data_mod[(rt_data_mod$participant_id %in% subj),'Correct_RT_logz'] <- (rt_data_mod[(rt_data_mod$participant_id %in% subj),'Correct_RT_log'] - temp_mean)/temp_sd
}
plot1 <- ggplot(rt_data_mod, aes(x=Correct_RT)) + geom_histogram() + theme_classic()

plot2 <- ggplot(rt_data_mod, aes(x=Correct_RT_logz)) + geom_histogram() + theme_classic()

grid.arrange(plot1, plot2, ncol=2)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

The raw reaction times are not normally distributed and right-skewed. This may be a result of the task design where participants were given a window to view the interest and the peer condition, then a separate window to respond. So all participants were forced to view the condition for the same amount of time. After our log and z-transform, we have a normal distribution for the reaction times.

Lastly, we will set the similar peer condition as the reference group for the regression analyses

rt_data_mod$Condition <- relevel(factor(rt_data_mod$Condition), ref = "SimPeer")

3 Non-Autistic Adolescents

rt_data_mod_typ <- filter(rt_data_mod, group == 'non-autistic')
print(paste("There are ",length(unique(rt_data_mod_typ$participant_id)), 
            " autistic participants"))
## [1] "There are  71  autistic participants"

3.1 Run and Reaction Time

Use a linear mixed-effects model to model both the fixed effects of our conditions of interest, and the random effects of the participants. An example of a random effect would be that some participants are just faster to respond in all conditions.

model_run_typ <- lmer(Correct_RT_logz ~ Run + (1 + Run | participant_id), 
                data = rt_data_mod_typ)
## boundary (singular) fit: see help('isSingular')
summary(model_run_typ)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Correct_RT_logz ~ Run + (1 + Run | participant_id)
##    Data: rt_data_mod_typ
## 
## REML criterion at convergence: 15486.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.0888 -0.6838 -0.1233  0.5858  5.4405 
## 
## Random effects:
##  Groups         Name        Variance Std.Dev. Corr 
##  participant_id (Intercept) 0.18239  0.4271        
##                 Run         0.02957  0.1720   -1.00
##  Residual                   0.93215  0.9655        
## Number of obs: 5557, groups:  participant_id, 71
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)  0.26671    0.06113 73.14865   4.363 4.14e-05 ***
## Run         -0.10794    0.02411 72.23839  -4.478 2.76e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##     (Intr)
## Run -0.976
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')

This analysis shows that participants are getting faster at responding throughout the task (B = -0.09, p = .0002).

ggplot(data = rt_data_mod_typ, aes(x=Run, y=Correct_RT_logz, group=Run)) + 
  geom_boxplot(outlier.shape = NA) + 
  geom_jitter(color='black', alpha=0.05) + 
  theme_classic()
## Warning: Removed 69 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 69 rows containing missing values (`geom_point()`).

The box plots show this significant tread, and the individual response times for all participants.

3.2 Peer Category and Run Predicting Reaction Time

Next, we will examine whether there are differences in reaction time to our peer conditions throughout the task. Again, the conditions were were getting feedback from a similar peer (75% positive feedback), dissimilar peer (25% positive feedback), or a random computer (50% positive feedback).

model_run_peer_typ <- lmer(Correct_RT_logz ~ Run*Condition + (1 + Run*Condition | participant_id),
                       data = rt_data_mod_typ)
## boundary (singular) fit: see help('isSingular')
## Warning: Model failed to converge with 3 negative eigenvalues: -1.5e-01
## -1.4e+00 -1.0e+02
summary(model_run_peer_typ)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: 
## Correct_RT_logz ~ Run * Condition + (1 + Run * Condition | participant_id)
##    Data: rt_data_mod_typ
## 
## REML criterion at convergence: 15486.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.0482 -0.6812 -0.1159  0.5885  5.4930 
## 
## Random effects:
##  Groups         Name                  Variance Std.Dev. Corr                   
##  participant_id (Intercept)           0.161074 0.40134                         
##                 Run                   0.025357 0.15924  -1.00                  
##                 ConditionComputer     0.006098 0.07809   0.48 -0.48            
##                 ConditionDisPeer      0.012762 0.11297   0.35 -0.35 -0.31      
##                 Run:ConditionComputer 0.001925 0.04387  -0.38  0.38 -0.94  0.58
##                 Run:ConditionDisPeer  0.003678 0.06065  -0.34  0.34  0.32 -1.00
##  Residual                             0.926726 0.96267                         
##       
##       
##       
##       
##       
##       
##  -0.59
##       
## Number of obs: 5557, groups:  participant_id, 71
## 
## Fixed effects:
##                         Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)             0.298086   0.073247  86.458495   4.070 0.000104 ***
## Run                    -0.126215   0.027979  83.828556  -4.511 2.08e-05 ***
## ConditionComputer      -0.045938   0.077261 394.588300  -0.595 0.552465    
## ConditionDisPeer       -0.048115   0.078058 422.946618  -0.616 0.537962    
## Run:ConditionComputer   0.050518   0.028858 176.417682   1.751 0.081759 .  
## Run:ConditionDisPeer    0.004372   0.029386 189.857379   0.149 0.881891    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) Run    CndtnC CndtDP Rn:CnC
## Run         -0.951                            
## CondtnCmptr -0.479  0.415                     
## ConditnDsPr -0.472  0.409  0.479              
## Rn:CndtnCmp  0.419 -0.445 -0.910 -0.417       
## Rn:CndtnDsP  0.401 -0.426 -0.422 -0.912  0.440
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')

Accounting for the peer condition, task run had a significant impact on reaction times (B = -0.11, p < .001), such that participants were getting faster as the task went on. There was no significant main effect of peer condition. There is a trend for an interaction in which participants had faster reaction times throughout the task for the similar peer condition, in comparison to the computer control condition (B = .05, p = 0.05).

ggplot(data = rt_data_mod_typ, aes(x=factor(Run), y=Correct_RT_logz, fill=Condition)) + 
  geom_boxplot(outlier.shape = NA) + 
  geom_point(alpha=0.05, aes(fill=Condition),
             position = position_jitterdodge(dodge.width = 0.8)) +
  theme_classic()
## Warning: Removed 69 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 69 rows containing missing values (`geom_point()`).

tab_model(model_run_peer_typ)
  Correct_RT_logz
Predictors Estimates CI p
(Intercept) 0.30 0.15 – 0.44 <0.001
Run -0.13 -0.18 – -0.07 <0.001
Condition [Computer] -0.05 -0.20 – 0.11 0.552
Condition [DisPeer] -0.05 -0.20 – 0.10 0.538
Run × Condition
[Computer]
0.05 -0.01 – 0.11 0.080
Run × Condition [DisPeer] 0.00 -0.05 – 0.06 0.882
Random Effects
σ2 0.93
τ00 participant_id 0.16
τ11 participant_id.Run 0.03
τ11 participant_id.ConditionComputer 0.01
τ11 participant_id.ConditionDisPeer 0.01
τ11 participant_id.Run:ConditionComputer 0.00
τ11 participant_id.Run:ConditionDisPeer 0.00
ρ01 -1.00
0.48
0.35
-0.38
-0.34
N participant_id 71
Observations 5557
Marginal R2 / Conditional R2 0.019 / NA
plot_model(model_run_peer_typ, type="pred", terms=c("Run","Condition"), 
           pred.type="re", ci.lvl=NA) + 
  theme_classic()

rt_data_mod_typ_means <- aggregate(Correct_RT_logz ~ participant_id * Run * Condition, rt_data_mod_typ, mean)

rt_data_mod_typ_means$Condition <- factor(rt_data_mod_typ_means$Condition, 
                                          levels=c('SimPeer', 'DisPeer', 'Computer'))

ggplot(data=rt_data_mod_typ_means, aes(x=factor(Run), y=Correct_RT_logz, 
                                       group=Condition, color=Condition)) + 
  geom_smooth(method='lm') + 
  geom_jitter(alpha=0.2) + 
  scale_color_manual(values=c('#1f77b4', '#ff7f0e', '#2ca02c'),
                     labels=c('Similar Peer', 'Dissimilar Peer', 'Computer')) + 
  theme_classic()
## `geom_smooth()` using formula = 'y ~ x'

3.3 Previous Feedback and Run Predicting Reaction Time

Another way we can look at reaction time is to examine if reaction times would be effected by the valence of the previous trial from the same condition. For example, when considering to learn about “Shiloh” in the current trial, if Shiloh had given negative feedback in their last trial, perhaps the participants would be less motivated to learn about Shiloh in the current trial.

model_run_prev_val_typ <- lmer(Correct_RT_logz ~ Run*Valence_prev + (1 + Run*Valence_prev | participant_id),
                       data = rt_data_mod_typ)
## boundary (singular) fit: see help('isSingular')
summary(model_run_prev_val_typ)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Correct_RT_logz ~ Run * Valence_prev + (1 + Run * Valence_prev |  
##     participant_id)
##    Data: rt_data_mod_typ
## 
## REML criterion at convergence: 13573.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.1117 -0.6873 -0.1227  0.5757  5.3371 
## 
## Random effects:
##  Groups         Name                     Variance Std.Dev. Corr             
##  participant_id (Intercept)              0.203875 0.45153                   
##                 Run                      0.033889 0.18409  -0.99            
##                 Valence_prevpositive     0.002889 0.05375   0.13  0.00      
##                 Run:Valence_prevpositive 0.004710 0.06863  -0.05 -0.08 -1.00
##  Residual                                0.925757 0.96216                   
## Number of obs: 4867, groups:  participant_id, 71
## 
## Fixed effects:
##                            Estimate Std. Error         df t value Pr(>|t|)   
## (Intercept)                 0.19207    0.07321   78.52034   2.623  0.01045 * 
## Run                        -0.08599    0.02874   75.47831  -2.992  0.00375 **
## Valence_prevpositive       -0.01686    0.06747 1034.26526  -0.250  0.80269   
## Run:Valence_prevpositive    0.01903    0.02638  128.07951   0.722  0.47185   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) Run    Vlnc_p
## Run         -0.957              
## Vlnc_prvpst -0.455  0.400       
## Rn:Vlnc_prv  0.391 -0.439 -0.889
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
ggplot(data = subset(rt_data_mod_typ, !is.na(Valence_prev)), aes(x=factor(Run), y=Correct_RT_logz, fill=Valence_prev)) + 
  geom_boxplot(outlier.shape = NA) + 
  geom_point(alpha=0.05, aes(fill=Valence_prev),
             position = position_jitterdodge(dodge.width = 0.8)) +
  theme_classic()
## Warning: Removed 63 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 63 rows containing missing values (`geom_point()`).

The valence of the previous within condition trial did not have an impact on reaction times.

3.4 Previous Feedback, Peer Condition, and Run Predicting Reaction Time

Since the previous analysis failed, maybe explicitly adding an interaction for the peer condition will have an impact on reaction times. For example, the valence of the trial might be more salient when it is a similar peer who previously gave you positive feedback or a dissimilar peer who previously gave you negative feedback.

model_run_prev_val_cond_typ <- lmer(Correct_RT_logz ~ Run*Condition*Valence_prev + (1 + Run*Condition*Valence_prev | participant_id),
                       data = rt_data_mod_typ)
## boundary (singular) fit: see help('isSingular')
summary(model_run_prev_val_cond_typ)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Correct_RT_logz ~ Run * Condition * Valence_prev + (1 + Run *  
##     Condition * Valence_prev | participant_id)
##    Data: rt_data_mod_typ
## 
## REML criterion at convergence: 13567.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.0575 -0.6785 -0.1196  0.5754  5.2577 
## 
## Random effects:
##  Groups         Name                                       Variance Std.Dev.
##  participant_id (Intercept)                                0.45760  0.6765  
##                 Run                                        0.05506  0.2346  
##                 ConditionComputer                          0.33736  0.5808  
##                 ConditionDisPeer                           0.21791  0.4668  
##                 Valence_prevpositive                       0.27016  0.5198  
##                 Run:ConditionComputer                      0.02742  0.1656  
##                 Run:ConditionDisPeer                       0.01190  0.1091  
##                 Run:Valence_prevpositive                   0.03281  0.1811  
##                 ConditionComputer:Valence_prevpositive     0.29038  0.5389  
##                 ConditionDisPeer:Valence_prevpositive      0.10628  0.3260  
##                 Run:ConditionComputer:Valence_prevpositive 0.03210  0.1792  
##                 Run:ConditionDisPeer:Valence_prevpositive  0.01434  0.1198  
##  Residual                                                  0.90710  0.9524  
##  Corr                                                             
##                                                                   
##  -0.96                                                            
##  -0.75  0.55                                                      
##  -0.72  0.58  0.94                                                
##  -0.77  0.62  0.98  0.92                                          
##   0.74 -0.59 -0.95 -0.86 -0.99                                    
##   0.64 -0.60 -0.74 -0.92 -0.76  0.67                              
##   0.70 -0.67 -0.77 -0.85 -0.86  0.84  0.88                        
##   0.83 -0.66 -0.96 -0.84 -0.96  0.96  0.62  0.73                  
##   0.80 -0.65 -0.96 -0.91 -0.99  0.97  0.75  0.84  0.97            
##  -0.85  0.75  0.90  0.85  0.97 -0.97 -0.73 -0.90 -0.94 -0.96      
##  -0.63  0.72  0.39  0.40  0.57 -0.60 -0.48 -0.77 -0.52 -0.60  0.74
##                                                                   
## Number of obs: 4867, groups:  participant_id, 71
## 
## Fixed effects:
##                                              Estimate Std. Error         df
## (Intercept)                                  0.169933   0.135820  80.711967
## Run                                         -0.098472   0.049022  90.356700
## ConditionComputer                            0.090083   0.153944  89.893324
## ConditionDisPeer                            -0.019199   0.139531 111.537988
## Valence_prevpositive                        -0.004796   0.142557  95.538236
## Run:ConditionComputer                        0.022615   0.054309 121.926969
## Run:ConditionDisPeer                         0.013851   0.048851 204.419911
## Run:Valence_prevpositive                     0.029343   0.052194  97.682073
## ConditionComputer:Valence_prevpositive      -0.093512   0.183654 131.031677
## ConditionDisPeer:Valence_prevpositive        0.076817   0.184357 289.523781
## Run:ConditionComputer:Valence_prevpositive   0.005389   0.067034 150.555782
## Run:ConditionDisPeer:Valence_prevpositive   -0.056747   0.068231 187.015935
##                                            t value Pr(>|t|)  
## (Intercept)                                  1.251   0.2145  
## Run                                         -2.009   0.0476 *
## ConditionComputer                            0.585   0.5599  
## ConditionDisPeer                            -0.138   0.8908  
## Valence_prevpositive                        -0.034   0.9732  
## Run:ConditionComputer                        0.416   0.6778  
## Run:ConditionDisPeer                         0.284   0.7771  
## Run:Valence_prevpositive                     0.562   0.5753  
## ConditionComputer:Valence_prevpositive      -0.509   0.6115  
## ConditionDisPeer:Valence_prevpositive        0.417   0.6772  
## Run:ConditionComputer:Valence_prevpositive   0.080   0.9360  
## Run:ConditionDisPeer:Valence_prevpositive   -0.832   0.4066  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) Run    CndtnC CndtDP Vlnc_p Rn:CnC Rn:CDP Rn:Vl_ CnC:V_
## Run         -0.927                                                        
## CondtnCmptr -0.765  0.665                                                 
## ConditnDsPr -0.791  0.706  0.717                                          
## Vlnc_prvpst -0.810  0.720  0.730  0.751                                   
## Rn:CndtnCmp  0.696 -0.719 -0.913 -0.644 -0.668                            
## Rn:CndtnDsP  0.694 -0.752 -0.610 -0.902 -0.652  0.660                     
## Rn:Vlnc_prv  0.731 -0.786 -0.636 -0.682 -0.901  0.690  0.721              
## CndtnCmp:V_  0.647 -0.572 -0.817 -0.575 -0.774  0.756  0.493  0.682       
## CndtnDsP:V_  0.568 -0.513 -0.504 -0.709 -0.712  0.468  0.649  0.645  0.553
## Rn:CndtC:V_ -0.596  0.623  0.742  0.528  0.713 -0.814 -0.544 -0.759 -0.914
## Rn:CndDP:V_ -0.502  0.563  0.410  0.607  0.616 -0.475 -0.690 -0.693 -0.474
##             CDP:V_ R:CC:V
## Run                      
## CondtnCmptr              
## ConditnDsPr              
## Vlnc_prvpst              
## Rn:CndtnCmp              
## Rn:CndtnDsP              
## Rn:Vlnc_prv              
## CndtnCmp:V_              
## CndtnDsP:V_              
## Rn:CndtC:V_ -0.508       
## Rn:CndDP:V_ -0.897  0.534
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
ggplot(data = subset(rt_data_mod_typ, !is.na(Valence_prev)), aes(x=factor(Run), y=Correct_RT_logz, fill=Condition, alpha=Valence_prev)) + 
  geom_boxplot(outlier.shape = NA) + 
  theme_classic()
## Warning: Using alpha for a discrete variable is not advised.
## Warning: Removed 63 rows containing non-finite values (`stat_boxplot()`).

Makes no difference.

3.5 Are participants learning?

3.5.1 Reaction time difference between similar and dissimilar peers

In the later runs, is there a difference in reaction time between the similar and dissimilar peer conditions? How many participants show this learning effect?

rt_means_subj_cond_run_typ <- ddply(rt_data_mod_typ, c('participant_id','Condition','Run'), 
                                summarise, 
                                mean=mean(Correct_RT, na.rm=TRUE))

Calculate the difference in RT for similar and dissimilar peer conditions at run 4

r4_peer_diff_typ <- data.frame(matrix(ncol = 2, nrow = 0))

# Name columns for the empty dataframe  
colnames(r4_peer_diff_typ) <- c('ParticipantID', 'sim_dis_RT')

for (subj in unique(rt_means_subj_cond_run_typ$participant_id)) {
  temp_subj_data <- rt_means_subj_cond_run_typ[rt_means_subj_cond_run_typ$participant_id == subj, ]
  
  temp_last_run <- temp_subj_data$Run[length(unique(temp_subj_data$Run))]
  
  temp_run_data <- temp_subj_data[temp_subj_data$Run == temp_last_run, ]
  temp_diff <- temp_run_data[temp_run_data$Condition == 'SimPeer', 'mean'] - temp_run_data[temp_run_data$Condition == 'DisPeer', 'mean']
  
  r4_peer_diff_typ[nrow(r4_peer_diff_typ) + 1,] = c(subj,temp_diff)
}

r4_peer_diff_typ$sim_dis_RT <- as.numeric(r4_peer_diff_typ$sim_dis_RT) 

ggplot(r4_peer_diff_typ, aes(x=sim_dis_RT)) + geom_histogram() + theme_classic()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

prop_learn <- nrow(r4_peer_diff_typ[r4_peer_diff_typ$sim_dis_RT < 0, ]) / nrow(r4_peer_diff_typ)

print(paste(round(prop_learn, 4)*100, '% of participants had faster RTs for similar peers than dissimilar peers for their last run.'))
## [1] "46.48 % of participants had faster RTs for similar peers than dissimilar peers for their last run."
t.test(r4_peer_diff_typ$sim_dis_RT, alternative = "two.sided", var.equal = FALSE)
## 
##  One Sample t-test
## 
## data:  r4_peer_diff_typ$sim_dis_RT
## t = -0.51989, df = 70, p-value = 0.6048
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.03223817  0.01890633
## sample estimates:
##    mean of x 
## -0.006665919

3.5.2 Do participants show a decrease in RT after receiving positive feedback compared to negative feedback?

Note that previous valence here is the previous valence of the trial within the same condition.

rt_means_subj_pval_run_typ <- ddply(rt_data_mod_typ, c('participant_id','Valence_prev','Run'), 
                                summarise, 
                                mean=mean(Correct_RT, na.rm=TRUE))

# Remove rows with NA
rt_means_subj_pval_run_typ <- rt_means_subj_pval_run_typ[complete.cases(rt_means_subj_pval_run_typ), ]

Calculate the difference in RT for similar and dissimilar peer conditions at run 4

# Create a new column for for previous valence
r4_peer_diff_typ$pos_neg_RT <- NA

for (subj in unique(rt_means_subj_pval_run_typ$participant_id)) {
  temp_subj_data <- rt_means_subj_pval_run_typ[rt_means_subj_pval_run_typ$participant_id == subj, ]
  
  temp_last_run <- temp_subj_data$Run[length(unique(temp_subj_data$Run))]
  
  temp_run_data <- temp_subj_data[temp_subj_data$Run == temp_last_run, ]
  temp_diff <- temp_run_data[temp_run_data$Valence_prev == 'positive', 'mean'] - temp_run_data[temp_run_data$Valence_prev == 'negative', 'mean']
  
  r4_peer_diff_typ[r4_peer_diff_typ$ParticipantID == subj, 'pos_neg_RT'] = temp_diff
}

r4_peer_diff_typ$pos_neg_RT <- as.numeric(r4_peer_diff_typ$pos_neg_RT) 

ggplot(r4_peer_diff_typ, aes(x=pos_neg_RT)) + geom_histogram() + theme_classic()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

prop_learn <- nrow(r4_peer_diff_typ[r4_peer_diff_typ$pos_neg_RT < 0, ]) / nrow(r4_peer_diff_typ)

print(paste(round(prop_learn, 4)*100, '% of participants had faster RTs for trials that were precided by a positive outcome than negative outcomes, for their last run.'))
## [1] "43.66 % of participants had faster RTs for trials that were precided by a positive outcome than negative outcomes, for their last run."
t.test(r4_peer_diff_typ$pos_neg_RT, alternative = "two.sided", var.equal = FALSE)
## 
##  One Sample t-test
## 
## data:  r4_peer_diff_typ$pos_neg_RT
## t = 0.93053, df = 70, p-value = 0.3553
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.01477782  0.04062816
## sample estimates:
##  mean of x 
## 0.01292517

4 All Participants

4.1 Run and Reaction Time

Use a linear mixed-effects model to model both the fixed effects of our conditions of interest, and the random effects of the participants. An example of a random effect would be that some participants are just faster to respond in all conditions.

model_run <- lmer(Correct_RT_logz ~ Run + (1 + Run | participant_id), 
                data = rt_data_mod)
## boundary (singular) fit: see help('isSingular')
summary(model_run)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Correct_RT_logz ~ Run + (1 + Run | participant_id)
##    Data: rt_data_mod
## 
## REML criterion at convergence: 21672.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.0788 -0.6947 -0.1243  0.5858  5.4132 
## 
## Random effects:
##  Groups         Name        Variance Std.Dev. Corr 
##  participant_id (Intercept) 0.17537  0.4188        
##                 Run         0.02856  0.1690   -1.00
##  Residual                   0.93918  0.9691        
## Number of obs: 7758, groups:  participant_id, 97
## 
## Fixed effects:
##              Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)   0.21504    0.05106 100.23994   4.212 5.54e-05 ***
## Run          -0.08741    0.02016  98.90016  -4.336 3.49e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##     (Intr)
## Run -0.975
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')

This analysis shows that participants are getting faster at responding throughout the task (B = -0.09, p = .0002).

ggplot(data = rt_data_mod, aes(x=Run, y=Correct_RT_logz, group=Run)) + 
  geom_boxplot(outlier.shape = NA) + 
  geom_jitter(color='black', alpha=0.05) + 
  theme_classic()
## Warning: Removed 102 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 102 rows containing missing values (`geom_point()`).

The box plots show this significant tread, and the individual response times for all participants.

4.2 Peer Category and Run Predicting Reaction Time

Next, we will examine whether there are differences in reaction time to our peer conditions throughout the task. Again, the conditions were were getting feedback from a similar peer (75% positive feedback), dissimilar peer (25% positive feedback), or a random computer (50% positive feedback).

model_run_peer <- lmer(Correct_RT_logz ~ Run*Condition + (1 + Run*Condition | participant_id),
                       data = rt_data_mod)
## boundary (singular) fit: see help('isSingular')
summary(model_run_peer)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: 
## Correct_RT_logz ~ Run * Condition + (1 + Run * Condition | participant_id)
##    Data: rt_data_mod
## 
## REML criterion at convergence: 21673.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.0395 -0.6867 -0.1169  0.5905  5.4383 
## 
## Random effects:
##  Groups         Name                  Variance Std.Dev. Corr                   
##  participant_id (Intercept)           0.188580 0.43426                         
##                 Run                   0.027535 0.16594  -0.99                  
##                 ConditionComputer     0.037916 0.19472  -0.33  0.23            
##                 ConditionDisPeer      0.022074 0.14857  -0.16  0.04  0.96      
##                 Run:ConditionComputer 0.004725 0.06874   0.26 -0.23 -0.79 -0.62
##                 Run:ConditionDisPeer  0.001034 0.03216  -0.46  0.58 -0.61 -0.79
##  Residual                             0.932438 0.96563                         
##       
##       
##       
##       
##       
##       
##   0.27
##       
## Number of obs: 7758, groups:  participant_id, 97
## 
## Fixed effects:
##                        Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)             0.24517    0.06428 108.40121   3.814 0.000228 ***
## Run                    -0.10612    0.02415 111.63789  -4.394 2.55e-05 ***
## ConditionComputer      -0.03049    0.06793 141.69095  -0.449 0.654263    
## ConditionDisPeer       -0.06208    0.06661 262.32019  -0.932 0.352251    
## Run:ConditionComputer   0.03942    0.02504 162.97872   1.574 0.117367    
## Run:ConditionDisPeer    0.01769    0.02416 986.14291   0.732 0.464269    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) Run    CndtnC CndtDP Rn:CnC
## Run         -0.950                            
## CondtnCmptr -0.549  0.477                     
## ConditnDsPr -0.514  0.441  0.529              
## Rn:CndtnCmp  0.490 -0.519 -0.899 -0.462       
## Rn:CndtnDsP  0.406 -0.429 -0.453 -0.902  0.481
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')

Accounting for the peer condition, task run had a significant impact on reaction times (B = -0.11, p < .001), such that participants were getting faster as the task went on. There was no significant main effect of peer condition. There is a trend for an interaction in which participants had faster reaction times throughout the task for the similar peer condition, in comparison to the computer control condition (B = .05, p = 0.05).

ggplot(data = rt_data_mod, aes(x=factor(Run), y=Correct_RT_logz, fill=Condition)) + 
  geom_boxplot(outlier.shape = NA) + 
  geom_point(alpha=0.05, aes(fill=Condition),
             position = position_jitterdodge(dodge.width = 0.8)) +
  theme_classic()
## Warning: Removed 102 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 102 rows containing missing values (`geom_point()`).

4.3 Previous Feedback and Run Predicting Reaction Time

Another way we can look at reaction time is to examine if reaction times would be effected by the valence of the previous trial from the same condition. For example, when considering to learn about “Shiloh” in the current trial, if Shiloh had given negative feedback in their last trial, perhaps the participants would be less motivated to learn about Shiloh in the current trial.

model_run_prev_val <- lmer(Correct_RT_logz ~ Run*Valence_prev + (1 + Run*Valence_prev | participant_id),
                       data = rt_data_mod)
## boundary (singular) fit: see help('isSingular')
summary(model_run_prev_val)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Correct_RT_logz ~ Run * Valence_prev + (1 + Run * Valence_prev |  
##     participant_id)
##    Data: rt_data_mod
## 
## REML criterion at convergence: 18985.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.1100 -0.6960 -0.1197  0.5796  5.3267 
## 
## Random effects:
##  Groups         Name                     Variance Std.Dev. Corr             
##  participant_id (Intercept)              0.163457 0.40430                   
##                 Run                      0.028822 0.16977  -0.99            
##                 Valence_prevpositive     0.002169 0.04657   0.92 -0.86      
##                 Run:Valence_prevpositive 0.004111 0.06412  -0.22  0.05 -0.47
##  Residual                                0.932245 0.96553                   
## Number of obs: 6793, groups:  participant_id, 97
## 
## Fixed effects:
##                            Estimate Std. Error         df t value Pr(>|t|)  
## (Intercept)               1.131e-01  5.838e-02  1.108e+02   1.937   0.0553 .
## Run                      -5.623e-02  2.321e-02  1.053e+02  -2.423   0.0171 *
## Valence_prevpositive      4.369e-02  5.687e-02  2.109e+03   0.768   0.4424  
## Run:Valence_prevpositive -2.955e-03  2.211e-02  2.105e+02  -0.134   0.8938  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) Run    Vlnc_p
## Run         -0.948              
## Vlnc_prvpst -0.437  0.364       
## Rn:Vlnc_prv  0.382 -0.432 -0.876
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
ggplot(data = subset(rt_data_mod, !is.na(Valence_prev)), aes(x=factor(Run), y=Correct_RT_logz, fill=Valence_prev)) + 
  geom_boxplot(outlier.shape = NA) + 
  geom_point(alpha=0.05, aes(fill=Valence_prev),
             position = position_jitterdodge(dodge.width = 0.8)) +
  theme_classic()
## Warning: Removed 95 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 95 rows containing missing values (`geom_point()`).

The valence of the previous within condition trial did not have an impact on reaction times.

4.4 Previous Feedback, Peer Condition, and Run Predicting Reaction Time

Since the previous analysis failed, maybe explicitly adding an interaction for the peer condition will have an impact on reaction times. For example, the valence of the trial might be more salient when it is a similar peer who previously gave you positive feedback or a dissimilar peer who previously gave you negative feedback.

model_run_prev_val_cond <- lmer(Correct_RT_logz ~ Run*Condition*Valence_prev + (1 + Run*Condition*Valence_prev | participant_id),
                       data = rt_data_mod)
## boundary (singular) fit: see help('isSingular')
## Warning: Model failed to converge with 2 negative eigenvalues: -6.1e-01
## -1.1e+02
summary(model_run_prev_val_cond)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Correct_RT_logz ~ Run * Condition * Valence_prev + (1 + Run *  
##     Condition * Valence_prev | participant_id)
##    Data: rt_data_mod
## 
## REML criterion at convergence: 18983.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.0691 -0.6915 -0.1265  0.5762  5.2198 
## 
## Random effects:
##  Groups         Name                                       Variance Std.Dev.
##  participant_id (Intercept)                                0.322563 0.56795 
##                 Run                                        0.044978 0.21208 
##                 ConditionComputer                          0.168557 0.41056 
##                 ConditionDisPeer                           0.140101 0.37430 
##                 Valence_prevpositive                       0.166569 0.40813 
##                 Run:ConditionComputer                      0.019180 0.13849 
##                 Run:ConditionDisPeer                       0.008755 0.09357 
##                 Run:Valence_prevpositive                   0.032903 0.18139 
##                 ConditionComputer:Valence_prevpositive     0.090914 0.30152 
##                 ConditionDisPeer:Valence_prevpositive      0.055101 0.23474 
##                 Run:ConditionComputer:Valence_prevpositive 0.023351 0.15281 
##                 Run:ConditionDisPeer:Valence_prevpositive  0.015288 0.12365 
##  Residual                                                  0.915885 0.95702 
##  Corr                                                             
##                                                                   
##  -0.94                                                            
##  -0.71  0.52                                                      
##  -0.66  0.50  0.98                                                
##  -0.65  0.55  0.86  0.94                                          
##   0.74 -0.66 -0.87 -0.93 -0.98                                    
##   0.50 -0.50 -0.79 -0.87 -0.88  0.89                              
##   0.49 -0.59 -0.57 -0.69 -0.81  0.82  0.92                        
##   0.85 -0.77 -0.92 -0.93 -0.92  0.96  0.86  0.78                  
##   0.69 -0.60 -0.86 -0.89 -0.87  0.93  0.87  0.71  0.90            
##  -0.67  0.75  0.64  0.73  0.83 -0.86 -0.88 -0.97 -0.87 -0.72      
##  -0.45  0.60  0.30  0.37  0.47 -0.59 -0.65 -0.69 -0.54 -0.72  0.64
##                                                                   
## Number of obs: 6793, groups:  participant_id, 97
## 
## Fixed effects:
##                                              Estimate Std. Error         df
## (Intercept)                                  0.126760   0.108347 124.110597
## Run                                         -0.074185   0.040250 133.882554
## ConditionComputer                            0.029682   0.122816 167.774099
## ConditionDisPeer                            -0.048154   0.114280 190.548434
## Valence_prevpositive                         0.020867   0.115604 174.998753
## Run:ConditionComputer                        0.026038   0.045022 226.333188
## Run:ConditionDisPeer                         0.021078   0.040920 367.307883
## Run:Valence_prevpositive                     0.010058   0.044210 140.524566
## ConditionComputer:Valence_prevpositive      -0.016454   0.148025 426.123829
## ConditionDisPeer:Valence_prevpositive        0.069734   0.153860 707.930215
## Run:ConditionComputer:Valence_prevpositive  -0.003487   0.055916 284.396620
## Run:ConditionDisPeer:Valence_prevpositive   -0.038322   0.057690 334.711270
##                                            t value Pr(>|t|)  
## (Intercept)                                  1.170   0.2443  
## Run                                         -1.843   0.0675 .
## ConditionComputer                            0.242   0.8093  
## ConditionDisPeer                            -0.421   0.6740  
## Valence_prevpositive                         0.180   0.8570  
## Run:ConditionComputer                        0.578   0.5636  
## Run:ConditionDisPeer                         0.515   0.6068  
## Run:Valence_prevpositive                     0.228   0.8204  
## ConditionComputer:Valence_prevpositive      -0.111   0.9115  
## ConditionDisPeer:Valence_prevpositive        0.453   0.6505  
## Run:ConditionComputer:Valence_prevpositive  -0.062   0.9503  
## Run:ConditionDisPeer:Valence_prevpositive   -0.664   0.5070  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) Run    CndtnC CndtDP Vlnc_p Rn:CnC Rn:CDP Rn:Vl_ CnC:V_
## Run         -0.918                                                        
## CondtnCmptr -0.753  0.660                                                 
## ConditnDsPr -0.788  0.696  0.703                                          
## Vlnc_prvpst -0.790  0.710  0.691  0.742                                   
## Rn:CndtnCmp  0.697 -0.739 -0.904 -0.639 -0.649                            
## Rn:CndtnDsP  0.690 -0.750 -0.617 -0.901 -0.665  0.679                     
## Rn:Vlnc_prv  0.695 -0.779 -0.596 -0.650 -0.891  0.682  0.720              
## CndtnCmp:V_  0.611 -0.556 -0.795 -0.553 -0.744  0.733  0.500  0.664       
## CndtnDsP:V_  0.553 -0.500 -0.483 -0.703 -0.697  0.447  0.649  0.618  0.534
## Rn:CndtC:V_ -0.562  0.620  0.712  0.503  0.688 -0.800 -0.551 -0.759 -0.904
## Rn:CndDP:V_ -0.498  0.561  0.415  0.616  0.620 -0.477 -0.704 -0.686 -0.477
##             CDP:V_ R:CC:V
## Run                      
## CondtnCmptr              
## ConditnDsPr              
## Vlnc_prvpst              
## Rn:CndtnCmp              
## Rn:CndtnDsP              
## Rn:Vlnc_prv              
## CndtnCmp:V_              
## CndtnDsP:V_              
## Rn:CndtC:V_ -0.481       
## Rn:CndDP:V_ -0.901  0.528
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
ggplot(data = subset(rt_data_mod, !is.na(Valence_prev)), aes(x=factor(Run), y=Correct_RT_logz, fill=Condition, alpha=Valence_prev)) + 
  geom_boxplot(outlier.shape = NA) + 
  theme_classic()
## Warning: Using alpha for a discrete variable is not advised.
## Warning: Removed 95 rows containing non-finite values (`stat_boxplot()`).

Makes no difference.

4.5 Are participants learning?

4.5.1 Reaction time difference between similar and dissimilar peers

In the later runs, is there a difference in reaction time between the similar and dissimilar peer conditions? How many participants show this learning effect?

rt_means_subj_cond_run <- ddply(rt_data_mod,c('participant_id','Condition','Run'), 
                                summarise, 
                                mean=mean(Correct_RT, na.rm=TRUE))

Calculate the difference in RT for similar and dissimilar peer conditions at run 4

r4_peer_diff <- data.frame(matrix(ncol = 2, nrow = 0))

# Name columns for the empty dataframe  
colnames(r4_peer_diff) <- c('ParticipantID', 'sim_dis_RT')

for (subj in unique(rt_means_subj_cond_run$participant_id)) {
  temp_subj_data <- rt_means_subj_cond_run[rt_means_subj_cond_run$participant_id == subj, ]
  
  temp_last_run <- temp_subj_data$Run[length(unique(temp_subj_data$Run))]
  
  temp_run_data <- temp_subj_data[temp_subj_data$Run == temp_last_run, ]
  temp_diff <- temp_run_data[temp_run_data$Condition == 'SimPeer', 'mean'] - temp_run_data[temp_run_data$Condition == 'DisPeer', 'mean']
  
  r4_peer_diff[nrow(r4_peer_diff) + 1,] = c(subj,temp_diff)
}

r4_peer_diff$sim_dis_RT <- as.numeric(r4_peer_diff$sim_dis_RT) 

ggplot(r4_peer_diff, aes(x=sim_dis_RT)) + geom_histogram() + theme_classic()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

prop_learn <- nrow(r4_peer_diff[r4_peer_diff$sim_dis_RT < 0, ]) / nrow(r4_peer_diff)

print(paste(round(prop_learn, 4)*100, '% of participants had faster RTs for similar peers than dissimilar peers for their last run.'))
## [1] "50.52 % of participants had faster RTs for similar peers than dissimilar peers for their last run."
t.test(r4_peer_diff$sim_dis_RT, alternative = "two.sided", var.equal = FALSE)
## 
##  One Sample t-test
## 
## data:  r4_peer_diff$sim_dis_RT
## t = -0.77959, df = 96, p-value = 0.4376
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.02935397  0.01279877
## sample estimates:
##    mean of x 
## -0.008277599

4.5.2 Do participants show a decrease in RT after receiving positive feedback compared to negative feedback?

Note that previous valence here is the previous valence of the trial within the same condition.

rt_means_subj_pval_run <- ddply(rt_data_mod,c('participant_id','Valence_prev','Run'), 
                                summarise, 
                                mean=mean(Correct_RT, na.rm=TRUE))

# Remove rows with NA
rt_means_subj_pval_run <- rt_means_subj_pval_run[complete.cases(rt_means_subj_pval_run), ]

Calculate the difference in RT for similar and dissimilar peer conditions at run 4

# Create a new column for for previous valence
r4_peer_diff$pos_neg_RT <- NA

for (subj in unique(rt_means_subj_pval_run$participant_id)) {
  temp_subj_data <- rt_means_subj_pval_run[rt_means_subj_pval_run$participant_id == subj, ]
  
  temp_last_run <- temp_subj_data$Run[length(unique(temp_subj_data$Run))]
  
  temp_run_data <- temp_subj_data[temp_subj_data$Run == temp_last_run, ]
  temp_diff <- temp_run_data[temp_run_data$Valence_prev == 'positive', 'mean'] - temp_run_data[temp_run_data$Valence_prev == 'negative', 'mean']
  
  r4_peer_diff[r4_peer_diff$ParticipantID == subj, 'pos_neg_RT'] = temp_diff
}

r4_peer_diff$pos_neg_RT <- as.numeric(r4_peer_diff$pos_neg_RT) 

ggplot(r4_peer_diff, aes(x=pos_neg_RT)) + geom_histogram() + theme_classic()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

prop_learn <- nrow(r4_peer_diff[r4_peer_diff$pos_neg_RT < 0, ]) / nrow(r4_peer_diff)

print(paste(round(prop_learn, 4)*100, '% of participants had faster RTs for trials that were precided by a positive outcome than negative outcomes, for their last run.'))
## [1] "42.27 % of participants had faster RTs for trials that were precided by a positive outcome than negative outcomes, for their last run."
t.test(r4_peer_diff$sim_dis_RT, alternative = "two.sided", var.equal = FALSE)
## 
##  One Sample t-test
## 
## data:  r4_peer_diff$sim_dis_RT
## t = -0.77959, df = 96, p-value = 0.4376
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.02935397  0.01279877
## sample estimates:
##    mean of x 
## -0.008277599

5 Group Analyses

Next, we will analyze run by condition interactions for non-autistic adolescents and autistic adolescents, individually.


5.1 Autistic

rt_data_mod_asd <- filter(rt_data_mod, group == 'autistic')
print(paste("There are ",length(unique(rt_data_mod_asd$participant_id)), 
            " autistic participants"))
## [1] "There are  26  autistic participants"
model_run_peer_asd <- lmer(Correct_RT_logz ~ Run*Condition + (1 + Run | participant_id), data = rt_data_mod_asd)
## boundary (singular) fit: see help('isSingular')
summary(model_run_peer_asd)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Correct_RT_logz ~ Run * Condition + (1 + Run | participant_id)
##    Data: rt_data_mod_asd
## 
## REML criterion at convergence: 6208.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.6253 -0.7205 -0.1272  0.5891  4.1617 
## 
## Random effects:
##  Groups         Name        Variance Std.Dev. Corr 
##  participant_id (Intercept) 0.14048  0.3748        
##                 Run         0.02335  0.1528   -1.00
##  Residual                   0.95827  0.9789        
## Number of obs: 2201, groups:  participant_id, 26
## 
## Fixed effects:
##                         Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)              0.12183    0.11240   66.84448   1.084    0.282
## Run                     -0.05898    0.04344   59.18592  -1.358    0.180
## ConditionComputer       -0.01030    0.12073 2171.15342  -0.085    0.932
## ConditionDisPeer        -0.10338    0.12075 2171.08184  -0.856    0.392
## Run:ConditionComputer    0.01806    0.04458 2171.15272   0.405    0.685
## Run:ConditionDisPeer     0.05303    0.04452 2171.20737   1.191    0.234
## 
## Correlation of Fixed Effects:
##             (Intr) Run    CndtnC CndtDP Rn:CnC
## Run         -0.947                            
## CondtnCmptr -0.530  0.458                     
## ConditnDsPr -0.530  0.458  0.493              
## Rn:CndtnCmp  0.480 -0.506 -0.906 -0.447       
## Rn:CndtnDsP  0.480 -0.507 -0.447 -0.906  0.494
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')

In autistic adolescents, there are no significant main effects or interactions.

m.lst <- emtrends(model_run_peer_asd, "Condition", var="Run")
pairs(m.lst)
##  contrast           estimate     SE   df t.ratio p.value
##  SimPeer - Computer  -0.0181 0.0446 2148  -0.405  0.9136
##  SimPeer - DisPeer   -0.0530 0.0445 2150  -1.191  0.4586
##  Computer - DisPeer  -0.0350 0.0448 2148  -0.780  0.7152
## 
## Degrees-of-freedom method: kenward-roger 
## P value adjustment: tukey method for comparing a family of 3 estimates
ggplot(data = rt_data_mod_asd, aes(x=factor(Run), y=Correct_RT_logz, 
                                   fill=Condition)) + 
  geom_boxplot(outlier.shape = NA) + 
  geom_point(alpha=0.05, aes(fill=Condition),
             position = position_jitterdodge(dodge.width = 0.8)) +
  theme_classic()
## Warning: Removed 33 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 33 rows containing missing values (`geom_point()`).

5.2 Autistic vs Non-Autistic

In this analysis, we will examine specific contrasts between autistic and non-autistic adolescents. For example, we will test whether there are any group differences in reaction times for similar peers and the computer condition, throughout the task.